package edu.uoc.tdp.pac4.server;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.List;
import java.util.Locale;

import edu.uoc.tdp.pac4.beans.Attendance;
import edu.uoc.tdp.pac4.beans.AttendanceStudent;
import edu.uoc.tdp.pac4.beans.Course;
import edu.uoc.tdp.pac4.beans.Group;
import edu.uoc.tdp.pac4.beans.Registration;
import edu.uoc.tdp.pac4.beans.Usuari;
import edu.uoc.tdp.pac4.common.RegAndLogManagerInterface;
import edu.uoc.tdp.pac4.common.util.LanguageUtils;
import edu.uoc.tdp.pac4.database.AttendanceManager;
import edu.uoc.tdp.pac4.database.GroupManager;
import edu.uoc.tdp.pac4.database.LoginManager;
import edu.uoc.tdp.pac4.database.RegistrationManager;



public class RegAndLogManagerImpl extends java.rmi.server.UnicastRemoteObject
		implements RegAndLogManagerInterface, Serializable {

	private static final long serialVersionUID = 1L;
	RegistrationManager registrationManager = new RegistrationManager();
	GroupManager groupManager = new GroupManager();
	AttendanceManager attendanceManager = new AttendanceManager();
	
	public RegAndLogManagerImpl() throws RemoteException {
		super();
	}

	public RegAndLogManagerImpl(int port) throws RemoteException {
		super(port);
	}


	/**
	 * Set the language of the application 
	 */
	public void setLanguage(String baseName, Locale locale) throws RemoteException {
		LanguageUtils.setLanguage(baseName, locale);		
	}

	
	/**
	 * Method to do the login and get the user with his details, included the Rol
	 * 
	 */
	
	public Usuari login(String username, String password) throws RemoteException {
		return LoginManager.login(username, password);
	}

	

	public List<Registration> getAllRegByStudent(String idUsuari) throws RemoteException{
		List<Registration> regs = registrationManager.getAllRegByStudent(idUsuari);
		return regs;
	}


	public List<Registration> getAllAcceptedRegByStudent(String idUsuari)	throws RemoteException {
		List<Registration> regs = registrationManager.getAcceptedRegByStudent(idUsuari);
		return regs;
	}
	
	public List<Registration> getAllDeclinedRegByStudent(String idUsuari) throws RemoteException {
		List<Registration> regs = registrationManager.getDeclinedRegByStudent(idUsuari);
		return regs;
	}
	
	
	public List<Registration> getAllPendingRegByStudent(String idUsuari) throws RemoteException {
		List<Registration> regs = registrationManager.getPendingRegByStudent(idUsuari);
		return regs;
	}
	
	
	public List<Group> getNoStartedGroupsByCourse(Course course) throws RemoteException {
		List<Group> groups = groupManager.getNoStartedGroupsByCourse(course);
		return groups;
	}
	
	public boolean checkNewRegistration(Registration registration) throws RemoteException{
		return registrationManager.checkNewRegistration(registration);
	}
	public List<Attendance> getAttendancesByStudent(List<Registration> regs)throws RemoteException{
		return attendanceManager.getAttendancesByStudent(regs);
	}
	
	public boolean checkInAssistanceStudent(AttendanceStudent attstd) throws RemoteException{
		return attendanceManager.checkInAssistanceStudent(attstd);
	}
	public Attendance getAttendance(int attId) throws RemoteException{
		return attendanceManager.getAttendance(attId);
	}
}